package com.jeeplus.modules.sys.Job;

import com.jeeplus.modules.tools.utils.MultiDBUtils;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.SQLException;

/**
 * @author Administrator
 * @title: AppJob
 * @projectName JeePlus
 * @description: TODO
 * @date 2019/9/619:33
 */

public class AppJob {
 /*日志*/
 protected Logger logger = LoggerFactory.getLogger(getClass());
    public void startJob() {
        SchedulerFactory schedulerfactory = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            //获取调度器实例
            scheduler = schedulerfactory.getScheduler();
            // 指明job的名称，所在组的名称，以及绑定job类    创建jobDetail实例，绑定Job实现类
            JobDetailImpl jobDetail = new JobDetailImpl("appJob", "appGroup", myJob.class);

            //定义调度出发规则 每隔2秒执行一次
            CronTriggerImpl cornTrigger = new CronTriggerImpl("jobname", "jobgroup");

            //括号里面的*号依此为秒，分，时，天，周，月，年
            //里面有具体的使用规则，非常灵活
            cornTrigger.setCronExpression("0 0/1 * * * ? *");

            //把作业和触发器注册到任务调度中
            scheduler.scheduleJob(jobDetail, cornTrigger);
            //启动调度

            scheduler.start();
            scheduler.shutdown();
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
    public void testJob(){
        try {
            JdbcTemplate jdbc = MultiDBUtils.get("VSS").getJdbcTemplate();
            jdbc.execute("call vss.generate_uss_soa()");
            jdbc.getDataSource().getConnection().close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
